<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生产厂家" prop="drugVender">
        <el-select v-model="venderList1.drugVender" placeholder="生产厂家" clearable>
          <el-option
            v-for="dict in dict.type.psd_drug_vender"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="申请人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="单据状态" clearable>
          <el-option
            v-for="dict in dict.type.psd_purchase_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-update"
          size="mini"
          @click="updateStatus"
          :disabled="multiple"
          v-hasPermi="['psd:purchase:update']"
        >审核通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pssd:purchase:remove']"
        >审核不通过</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="purchaseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="单据ID"
        align="center"
        prop="purchaseDocuments"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="生产厂家" align="center" prop="purchaseVender" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.psd_drug_vender" :value="scope.row.purchaseVender"/>
        </template>
      </el-table-column>
      <el-table-column
        label="采购批发总额"
        align="center"
        prop="purchaseTotal"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.psd_purchase_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column
        label="申请人"
        align="center"
        prop="createBy"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="入库操作人" align="center" prop="updateBy" width="100" />
      <el-table-column label="入库时间" align="center" prop="updateTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.depotTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listPurchase,delPurchase,handleDelete, addNotice ,listVender,statusUpdate} from "@/api/pssd/examine";

export default {
  name: "Examine",
  dicts: ['psd_purchase_status', 'psd_drug_vender'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
        purchaseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
          purchaseId: undefined,
        /*noticeTitle: undefined,
        createBy: undefined,*/
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" }
        ]
      },
      venderList1:[],
      updateStatus1:[]
    };
  },
  created() {
    this.getList();

  },
  methods: {

      /** 修改按钮操作 */
      updateStatus() {
          this.reset();
          const purchaseId = this.ids
          statusUpdate(purchaseId).then(response => {
              this.form = response.data;
              this.open = true;
              this.title = "修改状态";
              this.handleQuery();
          });
          this.getList();
      },
      /** 查询公告列表 */
      getList() {
          this.loading = true;
          listPurchase(this.queryParams).then(response => {
              this.purchaseList = response.rows;
              this.total = response.total;
              this.loading = false;
          });

      },
      // 取消按钮
      cancel() {
          this.open = false;
          this.reset();
      },
      // 表单重置
      reset() {
          this.form = {
              /*noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,*/
              status: '0'
          };
          this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },


      /** 重置按钮操作 */
      resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
          console.log("sdf")
          this.ids = selection.map(item => item.purchaseId)
          this.single = selection.length != 1
          this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
          this.reset();
          this.open = true;
          this.title = "添加公告";
      },



      /** 删除按钮操作 */
      handleDelete(row) {
          const purchaseIds = row.purchaseIds |this.ids
          this.$modal.confirm('审核失败将会进行删除,是否确认删除编号为"' + purchaseIds + '"的数据项？').then(function () {
              return delPurchase(purchaseIds);
          }).then(() => {
              this.getList();
              this.$modal.msgSuccess("删除成功");
          }).catch(() => {
          });
      }
  }
};
</script>
